import os, Analysis,ResourceManager, DescriptionParser,string
from Configuration import Configuration

Configuration = Configuration()
Analysis.updateSkipList(1)

#for expName in ["1a7"]:
#    maxYear = 1
#    if expName == "1a4":
#        maxYear = 10
#    path = os.path.join("..", "das3_test_result")
#    Analysis.Configuration = Configuration
#    Configuration.path = path
#    print "min, max", DescriptionParser.getMinVarOfExp(expName), DescriptionParser.parseConfigureFile(expName)
#    for factor in xrange(DescriptionParser.getMinVarOfExp(expName), DescriptionParser.parseConfigureFile(expName)):
##        filenametemplate = "%d_"%expId + expName + "_%d_"%factor
#        filenametemplate = "_" + expName + "_%d_"%factor
#        curpath = os.path.join(path, expName)
#        for filename in os.listdir(curpath):
#            if filename.find(filenametemplate) < 0:
##                print "continue ", filename
#                continue
#            print "handle " + filename
#            expId = string.atoi( filename[:filename.find('_')])
#            pos1 = filename.find("node")
#            if pos1 <=0 :
#                pos1 = filename.find("router01")
#            pos2 = filename.find("_log")
#            hostname = filename[pos1:pos2]
##            print "the hostName is ", hostname
#            Configuration.hostname = hostname 
#            Configuration.setHostName(hostname)
#            Analysis.staticsCPUandMem(expId, expName, 1, 1, factor, factor, maxYear)

for expName in ["4a7-1024"]:
    maxYear = 1
    if expName == "1a4":
        maxYear = 10
    path = os.path.join("..", "das3_test_result")
    Analysis.Configuration = Configuration
    Configuration.path = path
    print "min, max", DescriptionParser.getMinVarOfExp(expName), DescriptionParser.parseConfigureFile(expName)
    for factor in xrange(DescriptionParser.getMinVarOfExp(expName), DescriptionParser.parseConfigureFile(expName)):
        filenametemplate = "_" + expName + "_%d_"%factor
        curpath = os.path.join(path, expName)
        for filename in os.listdir(curpath):
            if filename.find(filenametemplate) < 0 or filename.find("siqi")<0:
#                print "continue ", filename
                continue
            print "handle package " + filename
            expId = string.atoi( filename[:filename.find('_')])
            pos1 = filename.find("node")
            if pos1 <=0 :
                pos1 = filename.find("router01")
                if pos1 < 0:
                    pos1 =filename.find("siqi")
            pos2 = filename.find("_log")
            hostname = filename[pos1:pos2]
#            print "the hostName is ", hostname
            Configuration.hostname = hostname 
            Configuration.setHostName(hostname)
#            Analysis.staticsCPUandMem(expId, expName, 1, 1, factor, factor, maxYear)
            Analysis.network(expId, expName, 1, 1, factor, factor, maxYear, True)
            
            

